package com.dai.zhenfujin.message.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.dai.zhenfujin.R;
import com.dai.zhenfujin.message.bean.MessageBean;

import java.util.List;

public class MessageFragmentAdapter extends BaseAdapter {

    private Context context;
    private List<MessageBean> beanList;
    private LayoutInflater inflater;


    public MessageFragmentAdapter(Context context, List<MessageBean> beanList) {
        this.context = context;
        this.beanList = beanList;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return beanList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHodler hodler ;
        if(convertView == null){
            hodler = new ViewHodler();
            convertView = inflater.inflate(R.layout.message_listview,null);
            hodler.tvName = convertView.findViewById(R.id.message_name);
            hodler.tvCompany = convertView.findViewById(R.id.message_company);
            hodler.tvPost = convertView.findViewById(R.id.message_post);
            hodler.tvTime = convertView.findViewById(R.id.message_time);


            convertView.setTag(hodler);
        }else {
            hodler = (ViewHodler) convertView.getTag();
        }

        MessageBean bean = beanList.get(position);
        hodler.tvName.setText(bean.getName());
        hodler.tvPost.setText(bean.getPost());
        hodler.tvCompany.setText(bean.getCompany());

        return convertView;
    }
    class ViewHodler{

        private ImageView ivHead;
        private TextView tvName ,tvPost,tvCompany,tvTime;
    }
}
